package com.travel.pojo.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.time.LocalDateTime;

@Data
@TableName("users")
public class User {

    @TableId(type = IdType.AUTO)
    private Long id;

    private String username;

    private String password;

    private String phone;

    private Integer gender; // 1:男 2:女 3:其他

    private Integer age;

    private String ipLocation;


    private UserPermission userPermission;

    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @TableField("register_time")
    private LocalDateTime registerTime;

    public enum UserPermission {
        普通用户("普通用户"),
        VIP用户("VIP用户"),
        SVIP用户("SVIP用户");

        @EnumValue
        private final String description;

        UserPermission(String description) {
            this.description = description;
        }

        public String getDescription() {
            return description;
        }

        // 可选：添加从数据库值到枚举的转换方法
        public static UserPermission fromString(String value) {
            for (UserPermission permission : UserPermission.values()) {
                if (permission.getDescription().equals(value)) {
                    return permission;
                }
            }
            throw new IllegalArgumentException("无效的用户权限: " + value);
        }
    }
}